package com.clj.rocketmq_example.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.clj.rocketmq_example.dal.entity.UserEntity;
import com.clj.rocketmq_example.dal.mapper.UserMapper;
import com.clj.rocketmq_example.mq.RocketMqProducerService;
import com.clj.rocketmq_example.mq.command.MqConstant;
import com.clj.rocketmq_example.service.UserService;

import lombok.extern.slf4j.Slf4j;

@Slf4j
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, UserEntity> implements UserService{


    @Autowired
    private UserMapper userMapper;

    @Autowired
    private RocketMqProducerService rocketMqProducerService;

	@Override
	public UserEntity selectById(Long id) {
		return super.selectById(id);
	}

	@Override
	public Boolean save(UserEntity userEntity) {
		// TODO Auto-generated method stub
		return super.insert(userEntity);
	}

	@Override
	@Transactional(rollbackFor = Exception.class)
	public Boolean transMessageTest() {
		// 开始发送mq 事务消息
		UserEntity userEntity=new UserEntity();
		userEntity.setAge(11);
        userEntity.setUsername("trans");
        this.save(userEntity);
        //开始发送mq 事务消息
        log.info("begin send trans message");
        rocketMqProducerService.transSend(MqConstant.USER_ORDER_TOPIC,MqConstant.USER_TAG,"hello");
        log.info(" end send tran message");
        return true;
	}
	
}
